package com.itany.boot.entity;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/8/4 11:06
 * Version:1.0-SNAPSHOT
 * Description:
 */
@Component
// 当读取配置文件时,遇到指定的前缀,会将该前缀认为是当前对象
// 当使用prefix.xxx时,xxx表示该对象的属性
// 例如:此时prefix="user",配置中存在user.id=1
// 即:当前对象的id属性值为1
// 会自动将配置中的值注入到当前的属性中
@ConfigurationProperties(prefix = "user")
public class User {

//    @Value("${user.id}")
//    private Integer id;
//    @Value("${user.username}")
//    private String username;
//    @Value("${user.password}")
//    private String password;
//    @Value("${user.phone}")
//    private String phone;
//    @Value("${user.address}")
//    private String address;

//    @Value("${prefix.属性名}")
    private Integer id;
    private String username;
    private String password;
    private String phone;
    private String address;
    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", phone='" + phone + '\'' +
                ", address='" + address + '\'' +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}
